package com.zx.ishopping.controller.admin;


import com.zx.ishopping.VO.OrderItemsVo;
import com.zx.ishopping.entity.OrderItem;
import com.zx.ishopping.results.Result;
import com.zx.ishopping.services.OrderItemsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单详情
 */

@RestController
@RequestMapping("/admin/orderItems")
@Slf4j
public class orderItemsController {

    
    
    @Autowired
    private OrderItemsService orderItemsService;
    
    
    /**
     * 根据订单id查询订单详情
     * @param orderId 订单id
     * @return
     */
    @GetMapping("/getOrderItemsList/{orderId}")
    public Result<List<OrderItemsVo>> getOrderItemsList(@PathVariable Long orderId){
        List<OrderItemsVo> list =  orderItemsService.getOrderItemsList(orderId);
        return Result.success(list);
    }

    /**
     * 添加商品数量
     * @return
     */
    @PutMapping("/addNum")
    public Result addNum(Long id){
        orderItemsService.addNum(id);
        return Result.success();
    }


    /**
     * 减少商品数量
     * @param id
     * @return
     */
    @PutMapping("/reduceNum")
    public Result reduceNum(Long id){
        orderItemsService.reduceNum(id);
        return Result.success();
    }


    /**
     * 删除订单详情
     * @return
     */
    @DeleteMapping("/deleteOrderItem")
    public Result deleteOrderItem(@RequestParam Long id){
        orderItemsService.deleteOrderItem(id);
        return Result.success();
    }

}
